﻿Imports DTO
Imports System.Data.OleDb
Public Class GiaTriDinhSanDAO
    'Ham lay gia tri trong bang GiaTriDinhSan
    Public Function LayGiaTriDinhSan() As GiaTriDinhSanDTO
        Dim sql As String = "Select * From GiaTriDinhSan"
        Dim conn As OleDbConnection = DataProvider.ConnectDB()
        Dim cmd As New OleDbCommand(sql, conn)
        Dim reader As OleDbDataReader = cmd.ExecuteReader()
        Dim gtdsDTO As New GiaTriDinhSanDTO()
        While (reader.Read())
            gtdsDTO.LoaiTietKiem = reader.GetInt32("0")
            gtdsDTO.NgayGui = reader.GetDateTime("1")
            gtdsDTO.NgayRut = reader.GetDateTime("2")
        End While
        reader.Close()
        conn.Close()
        Return gtdsDTO
    End Function
    'Ham update gia tri dinh san
    Public Function CapNhatGiaTri(ByVal gtdsDTO As GiaTriDinhSanDTO) As Integer
        Dim sql As String = "Update GiaTriDinhSan Set LoaiTietKiem=@ltk,NgayGui=@ngaygui, NgayRut=@ngayrut"
        Dim conn As OleDbConnection = DataProvider.ConnectDB()
        Dim cmd As New OleDbCommand(sql, conn)
        Dim para As OleDbParameter
        para = cmd.Parameters.Add("@ltk", OleDbType.Integer)
        para.Value = gtdsDTO.LoaiTietKiem

        para = cmd.Parameters.Add("@ngaygui", OleDbType.DBDate)
        para.Value = gtdsDTO.NgayGui.Date

        para = cmd.Parameters.Add("@ngayrut", OleDbType.DBDate)
        para.Value = gtdsDTO.NgayRut.Date

        Dim kq As Integer = cmd.ExecuteNonQuery()
        conn.Close()
        If kq > 0 Then
            Return 1
        Else
            Return 0
        End If
    End Function
End Class
